package com.work.straighttalk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;


import com.facebook.drawee.view.SimpleDraweeView;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMVoiceMessageBody;
import com.work.straighttalk.R;

import butterknife.Bind;

/**
 * Created by dllo on 16/3/8.
 */
public class ReceiveVoiceHolder extends BaseViewHolder<EMMessage> {
    @Bind(R.id.btn_start)
    ImageButton btnStart;
    @Bind(R.id.sb_voice)
    SeekBar sbVoice;
    @Bind(R.id.sd_avater)
    SimpleDraweeView sdAvater;
    private OnRecyclerViewClickListener listener;

    public ReceiveVoiceHolder(Context context, ViewGroup root, OnRecyclerViewClickListener listener) {
        super(context, root, R.layout.item_receive_voice);
        this.listener = listener;
    }


    @Override
    public void bindData(EMMessage message) {
        final EMVoiceMessageBody body = (EMVoiceMessageBody) message.getBody();
        int seconds = body.getLength();
        sbVoice.setMax(seconds);
        if (message.status() == EMMessage.Status.SUCCESS) {
            btnStart.setClickable(true);
            btnStart.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onRecyclerViewCLick(body.getLocalUrl());
                }
            });
        } else {
            btnStart.setClickable(false);
        }
    }
}
